package com.bitbakery.plugin.lisp.lang.lexer;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public class LispSyntaxHighlighter extends SyntaxHighlighterBase {
    private static Map<IElementType, TextAttributesKey> keys;

    public static final TextAttributesKey COMMA = TextAttributesKey.createTextAttributesKey("LISP.COMMA", HighlighterColors.TEXT.getDefaultAttributes());
    public static final TextAttributesKey COMMA_AT = TextAttributesKey.createTextAttributesKey("LISP.COMMA_AT", HighlighterColors.TEXT.getDefaultAttributes());
    public static final TextAttributesKey BACKQUOTE = TextAttributesKey.createTextAttributesKey("LISP.BACKQUOTE", HighlighterColors.TEXT.getDefaultAttributes());

    public static final TextAttributesKey NUMERIC_LITERAL = TextAttributesKey.createTextAttributesKey("LISP.NUMERIC_LITERAL", HighlighterColors.JAVA_NUMBER.getDefaultAttributes());
    public static final TextAttributesKey STRING_LITERAL = TextAttributesKey.createTextAttributesKey("LISP.STRING_LITERAL", HighlighterColors.JAVA_STRING.getDefaultAttributes());
    public static final TextAttributesKey BAD_CHARACTER = TextAttributesKey.createTextAttributesKey("LISP.BAD_CHARACTER", HighlighterColors.BAD_CHARACTER.getDefaultAttributes());
    public static final TextAttributesKey BLOCK_COMMENT = TextAttributesKey.createTextAttributesKey("LISP.BLOCK_COMMENT", HighlighterColors.JAVA_LINE_COMMENT.getDefaultAttributes());
    public static final TextAttributesKey LINE_COMMENT = TextAttributesKey.createTextAttributesKey("LISP.LINE_COMMENT", HighlighterColors.JAVA_LINE_COMMENT.getDefaultAttributes());
    public static final TextAttributesKey DEFCONSTANT = TextAttributesKey.createTextAttributesKey("LISP.DEFCONSTANT", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey DEFMETHOD = TextAttributesKey.createTextAttributesKey("LISP.DEFMETHOD", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey DEFMACRO = TextAttributesKey.createTextAttributesKey("LISP.DEFMACRO", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey DEFCLASS = TextAttributesKey.createTextAttributesKey("LISP.DEFCLASS", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey DEFVAR = TextAttributesKey.createTextAttributesKey("LISP.DEFVAR", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey DEFUN = TextAttributesKey.createTextAttributesKey("LISP.DEFUN", HighlighterColors.JAVA_KEYWORD.getDefaultAttributes());
    public static final TextAttributesKey SYMBOL = TextAttributesKey.createTextAttributesKey("LISP.SYMBOL", HighlighterColors.TEXT.getDefaultAttributes());

    static {
        keys = new HashMap<IElementType, TextAttributesKey>();

        keys.put(LispTokenTypes.COMMA, COMMA);
        keys.put(LispTokenTypes.COMMA_AT, COMMA_AT);
        keys.put(LispTokenTypes.BACKQUOTE, BACKQUOTE);
        keys.put(LispTokenTypes.LINE_COMMENT, LINE_COMMENT);
        keys.put(LispTokenTypes.BLOCK_COMMENT, BLOCK_COMMENT);
        keys.put(LispTokenTypes.DEFUN, DEFUN);
        keys.put(LispTokenTypes.DEFMACRO, DEFMACRO);
        keys.put(LispTokenTypes.DEFVAR, DEFVAR);
        keys.put(LispTokenTypes.DEFCONSTANT, DEFCONSTANT);
        keys.put(LispTokenTypes.NUMERIC_LITERAL, NUMERIC_LITERAL);
        keys.put(LispTokenTypes.STRING_LITERAL, STRING_LITERAL);
        keys.put(LispTokenTypes.BAD_CHARACTER, BAD_CHARACTER);
        keys.put(LispTokenTypes.SYMBOL, SYMBOL);
    }

    @NotNull
    public Lexer getHighlightingLexer() {
        return new LispLexer();
    }

    @NotNull
    public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
        return pack(keys.get(tokenType));
    }
}
